package com.ultrasoft.farmasoft.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ultrasoft.farmasoft.domain.Item;
import com.ultrasoft.farmasoft.domain.Operation;
import com.ultrasoft.farmasoft.domain.Product;
import com.ultrasoft.farmasoft.domain.Transaction;
import com.ultrasoft.farmasoft.repository.ItemDao;
import com.ultrasoft.farmasoft.repository.OperationDao;
import com.ultrasoft.farmasoft.repository.ProductDao;
import com.ultrasoft.farmasoft.repository.TransactionDao;

@Service
public class ReportsServiceImpl implements ReportsService {

	private TransactionDao transactionDao;
	private OperationDao operationDao;
	private ItemDao itemDao;
	private ProductDao productDao;
	
	@Autowired
	public ReportsServiceImpl(ProductDao productDao,ItemDao itemDao,OperationDao operationDao,TransactionDao transactionDao){
		this.transactionDao  	= transactionDao;
		this.operationDao 		= operationDao;
		this.itemDao			= itemDao;
		this.productDao 		= productDao;
	}	
	@Transactional(readOnly = true)
	public List<Transaction> getListTransaction(){
		return transactionDao.getListTransaction();
	}
	@Transactional(readOnly = true)
	public List<Transaction> getListTransactionByDateTransaction(Date dateTransaction){
		List<Transaction> listTransaction = transactionDao.getListTransactionByDateTransaction(dateTransaction);
		for (Transaction transaction : listTransaction)
			transaction.setOperationId(searchByOperationId(transaction.getOperationId().getOperationId()));
		return listTransaction;
	}
	@Transactional(readOnly = true)
	public Transaction searchTransactionByPeriodIdsByTransactionId(Integer periodIds,Integer transactionId){
		return transactionDao.findTransactionByPeriodIdsByTransactionId(periodIds, transactionId);
	}
	@Transactional
    public void removeTransaction(Transaction transaction){
		transactionDao.remove(transaction);
	}
	@Transactional
    public void updateTransaction(Transaction transaction){
		transactionDao.update(transaction);
	}
	@Transactional
	public void addTransaction(Transaction transaction){
		transactionDao.add(transaction);
	}
	
	
	@Transactional(readOnly = true)
	public List<Operation> getListOperation(){
		return operationDao.getListOperation();
	}	
	@Transactional(readOnly = true)
    public Operation searchByOperationId(Short operationId){
		return operationDao.findByOperationId(operationId);
	}	
	@Transactional
    public void updateOperation(Operation operation){
    	operationDao.update(operation);
    }    
	@Transactional
    public void removeOperation(Operation operation){
    	operationDao.remove(operation);
    }   
	@Transactional
    public void addOperation(Operation operation){
    	operationDao.add(operation);
    }
		
	
	@Transactional(readOnly = true)
	public List<Object[]> getListObjectProductByStatePackageByStateItem(){
		return productDao.getListObjectProductByStatePackageByStateItem();

	}
}
